package com.huawei.springboot2023.business.warehouse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huawei.springboot2023.business.warehouse.dto.Warehouse;
import com.huawei.springboot2023.business.warehouse.service.IWarehouseService;
import com.huawei.springboot2023.core.dto.MyResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhouChengYang
 * @since 2023-04-07
 */
@RestController
@Slf4j
@RequestMapping("/warehouse")
public class WarehouseController {
    @Resource(name = "warehouseServiceImpl")
    private IWarehouseService warehouseService;


    /**
     * 获取当前用户的仓库列表
     * @param useName 用户姓名
     * @return
     */
    @GetMapping("/getWarehouseByUseName")
    @ResponseBody
    public MyResult getWarehouseByUseName(String useName){
        log.debug("新增台账----获取仓库列表");
        MyResult result = new MyResult();
        QueryWrapper<Warehouse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("useName",useName);
        queryWrapper.eq("isDelete",0);
        List<Warehouse> list = warehouseService.list(queryWrapper);
        if (list.size() > 0) {
            result.setMsg("查询仓库列表成功");
            result.setData(list);
        }else {
            result.setCode("9999");
            result.setMsg("您还没用申请仓库，请先申请");
        }
        return result;

    }

}
